package com.ailargemodel.common.exception;

import com.ailargemodel.common.BaseResponse;
import com.ailargemodel.common.ErrorCode;
import com.ailargemodel.common.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessExceptionHandler(BusinessException e) {
        log.error("businessException" + e.getMessage() ,e);
        return ResultUtil.error(e.getCode(), e.getMessage(),e.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeExceptionHasndler(RuntimeException e) {
        log.error("runtime error ",e);
        return ResultUtil.error(ErrorCode.SYSTEM_ERROR, e.getMessage(),"");
    }
}
